package com.huobao.yunying.activitys_store;

import java.util.List;
import java.util.Map;

import org.xutils.view.annotation.ViewInject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.adapters.Adapter_Youhuiquan;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.entity.Youhuiquan;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;

import android.view.View;
import android.widget.ListView;
import android.widget.RelativeLayout;

public class Act_Youhuiquan extends HuobaoBaseActivity {

	@ViewInject(R.id.listview)
	private ListView listview;
	private Adapter_Youhuiquan adapter;
	private String store_id;
	
	@ViewInject(R.id.rtly)
	private RelativeLayout layout;
	@Override
	protected int getContentView() {
		return R.layout.layout_youhuiquan;
	}

	@Override
	protected String getTitleText() {
		// TODO Auto-generated method stub
		return "优惠券";
	}

	@Override
	protected void init() {
		store_id = getIntent().getStringExtra("id");
		adapter = new Adapter_Youhuiquan(context);
		listview.setAdapter(adapter);
		getData();
	}

	private void getData(){
		Map<String, String> map = HttpUtil.getParams("app","store","act","coupon","id",store_id);
		Http.getInstant().sendRequest(context, map, new HttpListener() {
			
			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				List<Youhuiquan> list = JSON.parseArray(jsonObject.getString("retval"), Youhuiquan.class);
				if(list == null || list.size() == 0){
					layout.setVisibility(View.VISIBLE);
					listview.setVisibility(View.GONE);
				}else{
					layout.setVisibility(View.GONE);
					listview.setVisibility(View.VISIBLE);
					adapter.clear();
					adapter.addAll(list);
				}
			}
			
			@Override
			public void onHttpError(String error) {
				// TODO Auto-generated method stub
				
			}
		});
	}
}
